import Vue from 'vue'
import Vuex from 'vuex'
 
Vue.use(Vuex)
 
const store = new Vuex.Store({
    state: { //全局变量定义处
        hasLogin: false, //用户是否登录
        //token: "",  
        userInfo: {}, //用于存放用户账号数据
    },
    mutations: { //全局方法定义处
 
        //登录
        login(state, provider) {
            state.hasLogin = true;
            //state.userInfo = provider.user;
            //state.token = provider.token;
            state.userInfo=provider //将请求中的res.data.user对象存入userInfo
            uni.setStorage({//把用户信息保存到本地缓存
                key: 'userInfo',
                data: provider  
            })
        },
 
        //注销
        logout(state) {
            state.hasLogin = false;
            //state.token = false;
            state.userInfo = {};
            uni.removeStorage({
                key: 'userInfo' //根据键值移除对应位置的缓存数据
            })
        }
    },
   // actions: {
    
    //}
})
 
export default store